﻿using System;
using System.Collections.Generic;
using netDxf;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Tables;

namespace TestDxfDocument
{
    class Turningtool
    {
        public static void TurningtoolNo1(Dictionary<string, object> data)
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //作图
            //坐标
            double B = Convert.ToDouble(data["B"]);
            double H = Convert.ToDouble(data["H"]);
            double LH = Convert.ToDouble(data["LH"]);
            double EPSR = Convert.ToDouble(data["EPSR"]);
            double L = Convert.ToDouble(data["L"]);
            double KAPR = Convert.ToDouble(data["KAPR"]);
            double LF = Convert.ToDouble(data["LF"]);
            double WF = B - L * Math.Cos(KAPR * Math.PI / 180);
            string path = Convert.ToString(data["path"]);

            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(B, 0);
            Vector2 v3 = new Vector2(v2.X, -LF + L * Math.Sin(KAPR * Math.PI / 180));
            Vector2 v4 = new Vector2(WF, -LF);
            Vector2 v5 = new Vector2(0, -LF + WF * Math.Tan((180 - EPSR - KAPR) * Math.PI / 180));
            Vector2 v6 = new Vector2(0, v3.Y + v3.X * Math.Tan((180 - EPSR - KAPR) * Math.PI / 180));
            Vector2 v7 = new Vector2(0, -LF + LH);
            Vector2 v8 = new Vector2(B, v7.Y - B * Math.Tan((180 - EPSR - KAPR) * Math.PI / 180));
            Vector2 v9 = new Vector2(0, -H);
            Vector2 v10 = new Vector2(B, v9.Y);
            Vector2 v11 = new Vector2(v9.X, v9.Y - H);
            Vector2 v12 = new Vector2(v10.X, v10.Y - H);
            Vector2 v13 = new Vector2(v4.X + L, v4.Y);
            //线段
            Line Line1 = new Line(v1, v2);
            Line Line2 = new Line(v2, v3);
            Line Line3 = new Line(v3, v4);
            Line Line4 = new Line(v4, v5);
            Line Line5 = new Line(v5, v1);
            Line Line6 = new Line(v6, v3);
            Line Line7 = new Line(v7, v8);
            Line Line8 = new Line(v11, v12);
            Line Line9 = new Line(v9, v10);
            Line1.Layer = contour;
            Line2.Layer = contour;
            Line3.Layer = contour;
            Line4.Layer = contour;
            Line5.Layer = contour;
            Line6.Layer = contour;
            Line7.Layer = contour;
            Line8.Layer = refin;
            Line9.Layer = refin;
            dxf.AddEntity(Line1);
            dxf.AddEntity(Line2);
            dxf.AddEntity(Line3);
            dxf.AddEntity(Line4);
            dxf.AddEntity(Line5);
            dxf.AddEntity(Line6);
            dxf.AddEntity(Line7);
            dxf.AddEntity(Line8);
            dxf.AddEntity(Line9);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 1.0 / 2;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            LinearDimension dim1 = new LinearDimension(new Line(v1, v2), offset, 0, dimensionStyle);
            dim1.UserText = "B = " + Math.Round(B, 2);
            dxf.AddEntity(dim1);
            //尺寸2
            LinearDimension dim2 = new LinearDimension(new Line(v5, v4), -offset - WF / 2.00 * Math.Tan((180 - EPSR - KAPR) * Math.PI / 180), 0, dimensionStyle);
            dim2.UserText = "WF = " + Math.Round(WF, 2);
            dxf.AddEntity(dim2);
            //尺寸3
            LinearDimension dim3 = new LinearDimension(new Line(v9, v11), -offset, 270, dimensionStyle);
            dim3.UserText = "H = " + Math.Round(H, 2);
            dxf.AddEntity(dim3);
            //尺寸4
            LinearDimension dim4 = new LinearDimension(new Line(v7, v4), -offset - WF / 2.00, 270, dimensionStyle);
            dim4.UserText = "LH = " + Math.Round(LH, 2);
            dxf.AddEntity(dim4);
            //尺寸5
            LinearDimension dim5 = new LinearDimension(new Line(v2, v4), offset + 5 + (B - WF) / 2.00, 270, dimensionStyle);
            dim5.UserText = "LF = " + Math.Round(LF, 2);
            dxf.AddEntity(dim5);
            //尺寸6
            LinearDimension dim6 = new LinearDimension(new Line(v3, v4), offset, KAPR + 180, dimensionStyle);
            dim6.UserText = "L = " + Math.Round(L, 2);
            dxf.AddEntity(dim6);
            //尺寸7
            Angular2LineDimension dim7 = new Angular2LineDimension(new Line(v4, v13), new Line(v4, v3), offset + 5, dimensionStyle);
            dim7.UserText = String.Format("KAPR={0}°", KAPR);
            dxf.AddEntity(dim7);
            //尺寸8
            Angular2LineDimension dim8 = new Angular2LineDimension(new Line(v4, v3), new Line(v4, v5), offset, dimensionStyle);
            dim8.UserText = String.Format("EPSR={0}°", EPSR);
            dxf.AddEntity(dim8);
            //填充
            LwPolyline hatchpoly1 = new LwPolyline();
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v9));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v10));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v12));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v11));
            hatchpoly1.IsClosed = true;
            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)hatchpoly1.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, htype1, hnumst1, 45, 5, hline1, hatching);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void TurningtoolNo2(Dictionary<string, object> data)
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //作图
            //坐标
            double B = Convert.ToDouble(data["B"]);
            double H = Convert.ToDouble(data["H"]);
            double KAPR = Convert.ToDouble(data["KAPR"]);
            double LF = Convert.ToDouble(data["LF"]);
            double WF = Convert.ToDouble(data["WF"]);
            string path = Convert.ToString(data["path"]);
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(B, 0);
            Vector2 v3 = new Vector2(v2.X, -LF + B * Math.Sin(KAPR * Math.PI / 180) * Math.Cos(KAPR * Math.PI / 180) + (WF - B) * Math.Tan(KAPR * Math.PI / 180));
            Vector2 v4 = new Vector2(WF, -LF + B * Math.Sin(KAPR * Math.PI / 180) * Math.Cos(KAPR * Math.PI / 180));
            Vector2 v5 = new Vector2(WF - B * Math.Sin(KAPR * Math.PI / 180) * Math.Sin(KAPR * Math.PI / 180), -LF);
            Vector2 v6 = new Vector2(0, v3.Y);
            Vector2 v7 = new Vector2(0, -H);
            Vector2 v8 = new Vector2(B, v7.Y);
            Vector2 v9 = new Vector2(v7.X, v7.Y - H);
            Vector2 v10 = new Vector2(v8.X, v9.Y);
            Vector2 v11 = new Vector2(v4.X, v4.Y - B * Math.Sin(KAPR * Math.PI / 180));
            //线段
            Line Line1 = new Line(v1, v2);
            Line Line2 = new Line(v2, v3);
            Line Line3 = new Line(v3, v4);
            Line Line4 = new Line(v4, v5);
            Line Line5 = new Line(v5, v6);
            Line Line6 = new Line(v6, v1);
            Line Line7 = new Line(v7, v8);
            Line Line8 = new Line(v9, v10);
            Line1.Layer = contour;
            Line2.Layer = contour;
            Line3.Layer = contour;
            Line4.Layer = contour;
            Line5.Layer = contour;
            Line6.Layer = contour;
            Line7.Layer = refin;
            Line8.Layer = refin;
            dxf.AddEntity(Line1);
            dxf.AddEntity(Line2);
            dxf.AddEntity(Line3);
            dxf.AddEntity(Line4);
            dxf.AddEntity(Line5);
            dxf.AddEntity(Line6);
            dxf.AddEntity(Line7);
            dxf.AddEntity(Line8);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 1.0 / 2;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            LinearDimension dim1 = new LinearDimension(new Line(v1, v2), offset, 0, dimensionStyle);
            dim1.UserText = "B = " + Math.Round(B, 2);
            dxf.AddEntity(dim1);
            //尺寸2
            LinearDimension dim2 = new LinearDimension(new Line(v6, v4), -offset - 5 - (v6.Y - v4.Y) / 2.00 - (v4.Y - v5.Y), 0, dimensionStyle);
            dim2.UserText = "WF = " + Math.Round(WF, 2);
            dxf.AddEntity(dim2);
            //尺寸3
            LinearDimension dim3 = new LinearDimension(new Line(v7, v9), -offset, 270, dimensionStyle);
            dim3.UserText = "H = " + Math.Round(H, 2);
            dxf.AddEntity(dim3);
            //尺寸4
            LinearDimension dim4 = new LinearDimension(new Line(v2, v5), offset + (v4.X - v5.X) / 2.00, 270, dimensionStyle);
            dim4.UserText = "LF = " + Math.Round(LF, 2);
            dxf.AddEntity(dim4);
            //尺寸5
            Angular2LineDimension dim5 = new Angular2LineDimension(new Line(v4, v5), new Line(v4, v11), offset, dimensionStyle);
            dim5.UserText = String.Format("KAPR={0}°", KAPR);
            dxf.AddEntity(dim5);
            //填充
            LwPolyline hatchpoly1 = new LwPolyline();
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v7));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v8));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v10));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v9));
            hatchpoly1.IsClosed = true;
            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)hatchpoly1.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, htype1, hnumst1, 45, 5, hline1, hatching);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void TurningtoolNo3andNo6(Dictionary<string, object> data)
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //作图
            //坐标
            double B = Convert.ToDouble(data["B"]);
            double H = Convert.ToDouble(data["H"]);
            double KAPR = Convert.ToDouble(data["KAPR"]);
            double LF = Convert.ToDouble(data["LF"]);
            double WF = Convert.ToDouble(data["WF"]);
            double LH = Convert.ToDouble(data["LH"]);
            double HEA = Convert.ToDouble(data["HEA"]);
            double EPSR = Convert.ToDouble(data["EPSR"]);
            double ECA = Convert.ToDouble(data["ECA"]);
            double ECD = Convert.ToDouble(data["ECD"]);
            string path = Convert.ToString(data["path"]);
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(B, 0);
            Vector2 v3 = new Vector2(v2.X, -LF + LH);
            Vector2 v4 = new Vector2(WF - ((WF - B) * Math.Tan(HEA * Math.PI / 180) - LH) * Math.Tan((KAPR - 90) * Math.PI / 180) / (Math.Tan((KAPR - 90) * Math.PI / 180) / Math.Tan(HEA * Math.PI / 180) - 1), -LF + ((WF - B) * Math.Tan(HEA * Math.PI / 180) - LH) / (Math.Tan((KAPR - 90) * Math.PI / 180) / Math.Tan(HEA * Math.PI / 180) - 1));
            Vector2 v5 = new Vector2(WF, -LF);
            Vector2 v6 = new Vector2(ECD, (WF - ECD) * Math.Tan((180 - KAPR - EPSR) * Math.PI / 180) - LF);
            Vector2 v7 = new Vector2(0, v6.Y + ECD / Math.Tan(ECA * Math.PI / 180));
            Vector2 v8 = new Vector2(0, -H);
            Vector2 v9 = new Vector2(B, v8.Y);
            Vector2 v10 = new Vector2(v8.X, v8.Y - H);
            Vector2 v11 = new Vector2(v9.X, v10.Y);
            Vector2 v12 = new Vector2(v5.X + ((WF - B) * Math.Tan(HEA * Math.PI / 180) - LH) / (Math.Tan((KAPR - 90) * Math.PI / 180) / Math.Tan(HEA * Math.PI / 180) - 1), v5.Y);
            Vector2 v13 = new Vector2(0, v6.Y);
            Vector2 v14 = new Vector2(v4.X, v3.Y);
            //线段
            Line Line1 = new Line(v1, v2);
            Line Line2 = new Line(v2, v3);
            Line Line3 = new Line(v3, v4);
            Line Line4 = new Line(v4, v5);
            Line Line5 = new Line(v5, v6);
            Line Line6 = new Line(v6, v7);
            Line Line7 = new Line(v7, v1);
            Line Line8 = new Line(v8, v9);
            Line Line9 = new Line(v10, v11);
            Line1.Layer = contour;
            Line2.Layer = contour;
            Line3.Layer = contour;
            Line4.Layer = contour;
            Line5.Layer = contour;
            Line6.Layer = contour;
            Line7.Layer = contour;
            Line8.Layer = refin;
            Line9.Layer = refin;
            dxf.AddEntity(Line1);
            dxf.AddEntity(Line2);
            dxf.AddEntity(Line3);
            dxf.AddEntity(Line4);
            dxf.AddEntity(Line5);
            dxf.AddEntity(Line6);
            dxf.AddEntity(Line7);
            dxf.AddEntity(Line8);
            dxf.AddEntity(Line9);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 1.0 / 2;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            LinearDimension dim1 = new LinearDimension(new Line(v1, v2), offset, 0, dimensionStyle);
            dim1.UserText = "B = " + Math.Round(B, 2);
            dxf.AddEntity(dim1);
            //尺寸2
            LinearDimension dim2 = new LinearDimension(new Line(v7, v5), -offset - 15 - (v5.Y - v7.Y) / 2.00, 0, dimensionStyle);
            dim2.UserText = "WF = " + Math.Round(WF, 2);
            dxf.AddEntity(dim2);
            //尺寸3
            LinearDimension dim3 = new LinearDimension(new Line(v7, v6), -offset - 10 - (v6.Y - v7.Y) / 2.00, 0, dimensionStyle);
            dim3.UserText = "ECD = " + Math.Round(ECD, 2);
            dxf.AddEntity(dim3);
            //尺寸4
            LinearDimension dim4 = new LinearDimension(new Line(v2, v5), offset + 10 + (v5.X - v2.X) / 2.00, 270, dimensionStyle);
            dim4.UserText = "LF = " + Math.Round(LF, 2);
            dxf.AddEntity(dim4);
            //尺寸5
            Angular2LineDimension dim5 = new Angular2LineDimension(new Line(v5, v4), new Line(v5, v12), offset, dimensionStyle);
            dim5.UserText = String.Format("KAPR={0}°", KAPR);
            dxf.AddEntity(dim5);
            //尺寸6
            Angular2LineDimension dim6 = new Angular2LineDimension(new Line(v5, v4), new Line(v5, v6), offset, dimensionStyle);
            dim6.UserText = String.Format("EPSR={0}°", EPSR);
            dxf.AddEntity(dim6);
            //尺寸7
            Angular2LineDimension dim7 = new Angular2LineDimension(new Line(v7, v6), new Line(v7, v13), offset, dimensionStyle);
            dim7.UserText = String.Format("ECA={0}°", ECA);
            dxf.AddEntity(dim7);
            //尺寸8
            LinearDimension dim8 = new LinearDimension(new Line(v3, v5), offset + 5 + (v5.X - v3.X) / 2.00, 270, dimensionStyle);
            dim8.UserText = "LH = " + Math.Round(LH, 2);
            dxf.AddEntity(dim8);
            //尺寸9
            Angular2LineDimension dim9 = new Angular2LineDimension(new Line(v3, v14), new Line(v3, v4), offset, dimensionStyle);
            dim9.UserText = String.Format("HEA={0}°", HEA);
            dxf.AddEntity(dim9);
            //填充
            LwPolyline hatchpoly1 = new LwPolyline();
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v8));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v9));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v11));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v10));
            hatchpoly1.IsClosed = true;
            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)hatchpoly1.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, htype1, hnumst1, 45, 5, hline1, hatching);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void TurningtoolNo4(Dictionary<string, object> data)
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //作图
            //坐标
            double B = Convert.ToDouble(data["B"]);
            double H = Convert.ToDouble(data["H"]);
            double RAL = Convert.ToDouble(data["RAL"]);
            double RAR = Convert.ToDouble(data["RAR"]);
            double LF = Convert.ToDouble(data["LF"]);
            double CW = Convert.ToDouble(data["CW"]);
            double CDX = Convert.ToDouble(data["CDX"]);
            double HEA = Convert.ToDouble(data["HEA"]);
            string path = Convert.ToString(data["path"]);
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(B, 0);
            Vector2 v3 = new Vector2(v2.X, -LF + CDX);
            Vector2 v4 = new Vector2(B - ((CW - B - 2 * CDX * Math.Tan(RAR * Math.PI / 180)) / (-2) / (Math.Tan(HEA * Math.PI / 180) + Math.Tan(RAR * Math.PI / 180))) * Math.Tan(HEA * Math.PI / 180), v3.Y - ((CW - B - 2 * CDX * Math.Tan(RAR * Math.PI / 180)) / (-2) / (Math.Tan(HEA * Math.PI / 180) + Math.Tan(RAR * Math.PI / 180))));
            Vector2 v5 = new Vector2(B / 2.00 + CW / 2.00, -LF);
            Vector2 v6 = new Vector2(B / 2.00 - CW / 2.00, -LF);
            Vector2 v7 = new Vector2(v6.X + (CDX - ((CW - B - 2 * CDX * Math.Tan(RAL * Math.PI / 180)) / (-2) / (Math.Tan(HEA * Math.PI / 180) + Math.Tan(RAL * Math.PI / 180)))) * Math.Tan(RAL * Math.PI / 180), v6.Y + (CDX - ((CW - B - 2 * CDX * Math.Tan(RAL * Math.PI / 180)) / (-2) / (Math.Tan(HEA * Math.PI / 180) + Math.Tan(RAL * Math.PI / 180)))));
            Vector2 v8 = new Vector2(0, v3.Y);
            Vector2 v9 = new Vector2(0, -H);
            Vector2 v10 = new Vector2(B, v9.Y);
            Vector2 v11 = new Vector2(0, v9.Y - H);
            Vector2 v12 = new Vector2(v10.X, v11.Y);
            Vector2 v13 = new Vector2(v5.X, v4.Y);
            Vector2 v14 = new Vector2(v6.X, v7.Y);
            Vector2 v15 = new Vector2(v3.X + 5, v3.Y + 5);
            Vector2 v16 = new Vector2(v3.X, v15.Y);
            //线段
            Line Line1 = new Line(v1, v2);
            Line Line2 = new Line(v2, v3);
            Line Line3 = new Line(v3, v4);
            Line Line4 = new Line(v4, v5);
            Line Line5 = new Line(v5, v6);
            Line Line6 = new Line(v6, v7);
            Line Line7 = new Line(v7, v8);
            Line Line8 = new Line(v8, v1);
            Line Line9 = new Line(v9, v10);
            Line Line10 = new Line(v11, v12);
            Line1.Layer = contour;
            Line2.Layer = contour;
            Line3.Layer = contour;
            Line4.Layer = contour;
            Line5.Layer = contour;
            Line6.Layer = contour;
            Line7.Layer = contour;
            Line8.Layer = contour;
            Line9.Layer = refin;
            Line10.Layer = refin;
            dxf.AddEntity(Line1);
            dxf.AddEntity(Line2);
            dxf.AddEntity(Line3);
            dxf.AddEntity(Line4);
            dxf.AddEntity(Line5);
            dxf.AddEntity(Line6);
            dxf.AddEntity(Line7);
            dxf.AddEntity(Line8);
            dxf.AddEntity(Line9);
            dxf.AddEntity(Line10);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 1.0 / 2;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            LinearDimension dim1 = new LinearDimension(new Line(v1, v2), offset, 0, dimensionStyle);
            dim1.UserText = "B = " + Math.Round(B, 2);
            dxf.AddEntity(dim1);
            //尺寸2
            LinearDimension dim2 = new LinearDimension(new Line(v6, v5), -offset, 0, dimensionStyle);
            dim2.UserText = "CW = " + Math.Round(CW, 2);
            dxf.AddEntity(dim2);
            //尺寸3
            LinearDimension dim3 = new LinearDimension(new Line(v10, v12), offset, 270, dimensionStyle);
            dim3.UserText = "H = " + Math.Round(H, 2);
            dxf.AddEntity(dim3);
            //尺寸4
            LinearDimension dim4 = new LinearDimension(new Line(v2, v5), offset + 5 + (CW - B) / 2.00, 270, dimensionStyle);
            dim4.UserText = "LF = " + Math.Round(LF, 2);
            dxf.AddEntity(dim4);
            //尺寸5
            Angular2LineDimension dim5 = new Angular2LineDimension(new Line(v5, v4), new Line(v5, v13), offset, dimensionStyle);
            dim5.UserText = String.Format("RAR={0}°", RAR);
            dxf.AddEntity(dim5);
            //尺寸6
            Angular2LineDimension dim6 = new Angular2LineDimension(new Line(v6, v7), new Line(v6, v14), offset, dimensionStyle);
            dim6.UserText = String.Format("RAL={0}°", RAL);
            dxf.AddEntity(dim6);
            //尺寸7
            Angular2LineDimension dim7 = new Angular2LineDimension(new Line(v3, v15), new Line(v3, v16), offset, dimensionStyle);
            dim7.UserText = String.Format("HEA={0}°", HEA);
            dxf.AddEntity(dim7);
            //尺寸8
            LinearDimension dim8 = new LinearDimension(new Line(v3, v5), offset + (CW - B) / 2.00, 270, dimensionStyle);
            dim8.UserText = "CDX = " + Math.Round(CDX, 2);
            dxf.AddEntity(dim8);
            //填充
            LwPolyline hatchpoly1 = new LwPolyline();
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v9));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v10));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v12));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v11));
            hatchpoly1.IsClosed = true;
            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)hatchpoly1.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, htype1, hnumst1, 45, 5, hline1, hatching);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void TurningtoolNo5(Dictionary<string, object> data)
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //作图
            //坐标
            double B = Convert.ToDouble(data["B"]);
            double H = Convert.ToDouble(data["H"]);
            double ECA = Convert.ToDouble(data["ECA"]);
            double LH = Convert.ToDouble(data["LH"]);
            double LF = Convert.ToDouble(data["LF"]);
            double EPSR = Convert.ToDouble(data["EPSR"]);
            double KAPR = Convert.ToDouble(data["KAPR"]);
            double HEA = Convert.ToDouble(data["HEA"]);
            double ECD = Convert.ToDouble(data["ECD"]);
            double WF = Convert.ToDouble(data["WF"]);
            string path = Convert.ToString(data["path"]);
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(B, 0);
            Vector2 v3 = new Vector2(v2.X, -LF + LH);
            Vector2 v4 = new Vector2((((WF - B) * Math.Tan(HEA * Math.PI / 180) * Math.Tan((EPSR + KAPR - 90) * Math.PI / 180) - LH * Math.Tan(HEA * Math.PI / 180)) / (Math.Tan((EPSR + KAPR - 90) * Math.PI / 180) - Math.Tan(HEA * Math.PI / 180))) / Math.Tan(HEA * Math.PI / 180) + v3.X, v3.Y - ((WF - B) * Math.Tan(HEA * Math.PI / 180) * Math.Tan((EPSR + KAPR - 90) * Math.PI / 180) - LH * Math.Tan(HEA * Math.PI / 180)) / (Math.Tan((EPSR + KAPR - 90) * Math.PI / 180) - Math.Tan(HEA * Math.PI / 180)));
            Vector2 v5 = new Vector2(WF, -LF);
            Vector2 v6 = new Vector2(ECD, v5.Y - (WF - ECD) * Math.Cos(KAPR * Math.PI / 180) / Math.Sin(KAPR * Math.PI / 180));
            Vector2 v7 = new Vector2(0, v6.Y + ECD / Math.Tan(ECA * Math.PI / 180));
            Vector2 v8 = new Vector2(0, -H);
            Vector2 v9 = new Vector2(B, v8.Y);
            Vector2 v10 = new Vector2(0, v8.Y - H);
            Vector2 v11 = new Vector2(v9.X, v9.Y - H);
            Vector2 v12 = new Vector2(0, v6.Y);
            Vector2 v13 = new Vector2(v4.X, v3.Y);
            Vector2 v14 = new Vector2(v5.X, v5.Y - WF + ECD);
            //线段
            Line Line1 = new Line(v1, v2);
            Line Line2 = new Line(v2, v3);
            Line Line3 = new Line(v3, v4);
            Line Line4 = new Line(v4, v5);
            Line Line5 = new Line(v5, v6);
            Line Line6 = new Line(v6, v7);
            Line Line7 = new Line(v7, v1);
            Line Line8 = new Line(v8, v9);
            Line Line9 = new Line(v10, v11);
            Line1.Layer = contour;
            Line2.Layer = contour;
            Line3.Layer = contour;
            Line4.Layer = contour;
            Line5.Layer = contour;
            Line6.Layer = contour;
            Line7.Layer = contour;
            Line8.Layer = refin;
            Line9.Layer = refin;
            dxf.AddEntity(Line1);
            dxf.AddEntity(Line2);
            dxf.AddEntity(Line3);
            dxf.AddEntity(Line4);
            dxf.AddEntity(Line5);
            dxf.AddEntity(Line6);
            dxf.AddEntity(Line7);
            dxf.AddEntity(Line8);
            dxf.AddEntity(Line9);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 1.0 / 2;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            LinearDimension dim1 = new LinearDimension(new Line(v1, v2), offset, 0, dimensionStyle);
            dim1.UserText = "B = " + Math.Round(B, 2);
            dxf.AddEntity(dim1);
            //尺寸2
            LinearDimension dim2 = new LinearDimension(new Line(v7, v5), -offset - 10 - (v7.Y - v5.Y) / 2.00 - v6.Y + v5.Y, 0, dimensionStyle);
            dim2.UserText = "WF = " + Math.Round(WF, 2);
            dxf.AddEntity(dim2);
            //尺寸3
            LinearDimension dim3 = new LinearDimension(new Line(v8, v10), -offset, 270, dimensionStyle);
            dim3.UserText = "H = " + Math.Round(H, 2);
            dxf.AddEntity(dim3);
            //尺寸4
            LinearDimension dim4 = new LinearDimension(new Line(v2, v5), offset + 5 + (WF - B) / 2.00, 270, dimensionStyle);
            dim4.UserText = "LF = " + Math.Round(LF, 2);
            dxf.AddEntity(dim4);
            //尺寸5
            Angular2LineDimension dim5 = new Angular2LineDimension(new Line(v5, v4), new Line(v5, v6), offset, dimensionStyle);
            dim5.UserText = String.Format("EPSR={0}°", EPSR);
            dxf.AddEntity(dim5);
            //尺寸6
            Angular2LineDimension dim6 = new Angular2LineDimension(new Line(v7, v6), new Line(v7, v12), offset, dimensionStyle);
            dim6.UserText = String.Format("ECA={0}°", ECA);
            dxf.AddEntity(dim6);
            //尺寸7
            Angular2LineDimension dim7 = new Angular2LineDimension(new Line(v3, v4), new Line(v3, v13), offset, dimensionStyle);
            dim7.UserText = String.Format("HEA={0}°", HEA);
            dxf.AddEntity(dim7);
            //尺寸8
            LinearDimension dim8 = new LinearDimension(new Line(v3, v5), offset + (WF - B) / 2.00, 270, dimensionStyle);
            dim8.UserText = "LH = " + Math.Round(LH, 2);
            dxf.AddEntity(dim8);
            //尺寸9
            Angular2LineDimension dim9 = new Angular2LineDimension(new Line(v5, v6), new Line(v5, v14), offset * 3, dimensionStyle);
            dim9.UserText = String.Format("KAPR={0}°", KAPR);
            dxf.AddEntity(dim9);
            //尺寸10
            LinearDimension dim10 = new LinearDimension(new Line(v7, v6), -offset - 5 - (v7.Y - v6.Y) / 2.00, 0, dimensionStyle);
            dim10.UserText = "ECD = " + Math.Round(ECD, 2);
            dxf.AddEntity(dim10);
            //填充
            LwPolyline hatchpoly1 = new LwPolyline();
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v8));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v9));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v11));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v10));
            hatchpoly1.IsClosed = true;
            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)hatchpoly1.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, htype1, hnumst1, 45, 5, hline1, hatching);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void TurningtoolNo7(Dictionary<string, object> data)
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //作图
            //坐标
            double B = Convert.ToDouble(data["B"]);
            double H = Convert.ToDouble(data["H"]);
            double RAL = Convert.ToDouble(data["RAL"]);
            double RAR = Convert.ToDouble(data["RAR"]);
            double CDX = Convert.ToDouble(data["CDX"]);
            double LF = Convert.ToDouble(data["LF"]);
            double KAPR = Convert.ToDouble(data["KAPR"]);
            double HEA = Convert.ToDouble(data["HEA"]);
            double CW = Convert.ToDouble(data["CW"]);
            double WF = Convert.ToDouble(data["WF"]);
            string path = Convert.ToString(data["path"]);
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(B, 0);
            Vector2 v3 = new Vector2(v2.X, -LF + CDX + CW * Math.Tan((KAPR - 90) * Math.PI / 180));
            Vector2 v4 = new Vector2(v3.X - (B - WF + (CDX + CW * Math.Tan((KAPR - 90) * Math.PI / 180)) * Math.Tan(RAR * Math.PI / 180)), v3.Y - (B - WF + (CDX + CW * Math.Tan((KAPR - 90) * Math.PI / 180)) * Math.Tan(RAR * Math.PI / 180)) * Math.Tan(HEA * Math.PI / 180));
            Vector2 v5 = new Vector2(WF, -LF);
            Vector2 v6 = new Vector2(WF - CW, v5.Y + CW * Math.Tan((KAPR - 90) * Math.PI / 180));
            Vector2 v7 = new Vector2(v6.X + CDX * Math.Tan(RAL * Math.PI / 180), v6.Y + CDX);
            Vector2 v8 = new Vector2(0, v7.Y + v7.X * Math.Tan(HEA * Math.PI / 180));
            Vector2 v9 = new Vector2(0, -H);
            Vector2 v10 = new Vector2(B, v9.Y);
            Vector2 v11 = new Vector2(v9.X, v9.Y - H);
            Vector2 v12 = new Vector2(v10.X, v11.Y);
            Vector2 v13 = new Vector2(v4.X + 5, v4.Y);
            Vector2 v14 = new Vector2(v7.X - 5, v7.Y);
            Vector2 v15 = new Vector2(v6.X, v7.Y);
            Vector2 v16 = new Vector2(v5.X, v4.Y);
            Vector2 v17 = new Vector2(v5.X, v5.Y - v5.X + v6.X);
            //线段
            Line Line1 = new Line(v1, v2);
            Line Line2 = new Line(v2, v3);
            Line Line3 = new Line(v3, v4);
            Line Line4 = new Line(v4, v5);
            Line Line5 = new Line(v5, v6);
            Line Line6 = new Line(v6, v7);
            Line Line7 = new Line(v7, v8);
            Line Line8 = new Line(v8, v1);
            Line Line9 = new Line(v9, v10);
            Line Line10 = new Line(v11, v12);
            Line1.Layer = contour;
            Line2.Layer = contour;
            Line3.Layer = contour;
            Line4.Layer = contour;
            Line5.Layer = contour;
            Line6.Layer = contour;
            Line7.Layer = contour;
            Line8.Layer = contour;
            Line9.Layer = refin;
            Line10.Layer = refin;
            dxf.AddEntity(Line1);
            dxf.AddEntity(Line2);
            dxf.AddEntity(Line3);
            dxf.AddEntity(Line4);
            dxf.AddEntity(Line5);
            dxf.AddEntity(Line6);
            dxf.AddEntity(Line7);
            dxf.AddEntity(Line8);
            dxf.AddEntity(Line9);
            dxf.AddEntity(Line10);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 1.0 / 2;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            LinearDimension dim1 = new LinearDimension(new Line(v1, v2), offset, 0, dimensionStyle);
            dim1.UserText = "B = " + Math.Round(B, 2);
            dxf.AddEntity(dim1);
            //尺寸2
            LinearDimension dim2 = new LinearDimension(new Line(v8, v5), -offset - 5 - (v8.Y - v5.Y) / 2.00, 0, dimensionStyle);
            dim2.UserText = "WF = " + Math.Round(WF, 2);
            dxf.AddEntity(dim2);
            //尺寸3
            LinearDimension dim3 = new LinearDimension(new Line(v9, v11), -offset, 270, dimensionStyle);
            dim3.UserText = "H = " + Math.Round(H, 2);
            dxf.AddEntity(dim3);
            //尺寸4
            LinearDimension dim4 = new LinearDimension(new Line(v2, v5), offset + 5 + (WF - B) / 2.00, 270, dimensionStyle);
            dim4.UserText = "LF = " + Math.Round(LF, 2);
            dxf.AddEntity(dim4);
            //尺寸5
            Angular2LineDimension dim5 = new Angular2LineDimension(new Line(v4, v3), new Line(v4, v13), offset, dimensionStyle);
            dim5.UserText = String.Format("HEA={0}°", HEA);
            dxf.AddEntity(dim5);
            //尺寸6
            Angular2LineDimension dim6 = new Angular2LineDimension(new Line(v7, v8), new Line(v7, v14), offset, dimensionStyle);
            dim6.UserText = String.Format("HEA={0}°", HEA);
            dxf.AddEntity(dim6);
            //尺寸7
            Angular2LineDimension dim7 = new Angular2LineDimension(new Line(v6, v7), new Line(v6, v15), offset, dimensionStyle);
            dim7.UserText = String.Format("RAL={0}°", RAL);
            dxf.AddEntity(dim7);
            //尺寸8
            Angular2LineDimension dim8 = new Angular2LineDimension(new Line(v5, v4), new Line(v5, v16), offset, dimensionStyle);
            dim8.UserText = String.Format("RAR={0}°", RAR);
            dxf.AddEntity(dim8);
            //尺寸11
            LinearDimension dim11 = new LinearDimension(new Line(v7, v6), -offset - WF + CW - (v7.X - v6.X) / 2.00, 270, dimensionStyle);
            dim11.UserText = "CDX = " + Math.Round(CDX, 2);
            dxf.AddEntity(dim11);
            //尺寸9
            Angular2LineDimension dim9 = new Angular2LineDimension(new Line(v5, v6), new Line(v5, v17), offset * 3, dimensionStyle);
            dim9.UserText = String.Format("KAPR={0}°", KAPR);
            dxf.AddEntity(dim9);
            //尺寸10
            LinearDimension dim10 = new LinearDimension(new Line(v5, v6), -offset, 0, dimensionStyle);
            dim10.UserText = "CW = " + Math.Round(CW, 2);
            dxf.AddEntity(dim10);
            //填充
            LwPolyline hatchpoly1 = new LwPolyline();
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v9));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v10));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v12));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v11));
            hatchpoly1.IsClosed = true;
            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)hatchpoly1.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, htype1, hnumst1, 45, 5, hline1, hatching);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void TurningtoolPointedstraightdesign(Dictionary<string, object> data)
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //作图
            //坐标
            double B = Convert.ToDouble(data["B"]);
            double H = Convert.ToDouble(data["H"]);
            double LH = Convert.ToDouble(data["LH"]);
            double LF = Convert.ToDouble(data["LF"]);
            double KAPR = Convert.ToDouble(data["KAPR"]);
            double EPSR = 180 - KAPR * 2;
            double L = Convert.ToDouble(data["L"]);
            double WF = B / 2.00;
            string path = Convert.ToString(data["path"]);
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(B, 0);
            Vector2 v3 = new Vector2(v2.X, -LF + WF * Math.Tan(KAPR * Math.PI / 180));
            Vector2 v4 = new Vector2(WF, -LF);
            Vector2 v5 = new Vector2(0, v3.Y);
            Vector2 v6 = new Vector2(0, -LF + LH);
            Vector2 v7 = new Vector2(B, v6.Y);
            Vector2 v8 = new Vector2(WF - L / 2.00, v6.Y);
            Vector2 v9 = new Vector2(v8.X, -LF + (L / 2.00) * Math.Tan(KAPR * Math.PI / 180));
            Vector2 v10 = new Vector2(WF + L / 2.00, v8.Y);
            Vector2 v11 = new Vector2(v10.X, v9.Y);
            Vector2 v12 = new Vector2(0, -H);
            Vector2 v13 = new Vector2(B, v12.Y);
            Vector2 v14 = new Vector2(v12.X, v12.Y - H);
            Vector2 v15 = new Vector2(v13.X, v14.Y);
            Vector2 v16 = new Vector2(v3.X, v4.Y);
            Vector2 v17 = new Vector2(v5.X, v4.Y);
            //线段
            Line Line1 = new Line(v1, v2);
            Line Line2 = new Line(v2, v3);
            Line Line3 = new Line(v3, v4);
            Line Line4 = new Line(v4, v5);
            Line Line5 = new Line(v5, v1);
            Line Line6 = new Line(v6, v7);
            Line Line7 = new Line(v8, v9);
            Line Line8 = new Line(v10, v11);
            Line Line9 = new Line(v12, v13);
            Line Line10 = new Line(v14, v15);
            Line1.Layer = contour;
            Line2.Layer = contour;
            Line3.Layer = contour;
            Line4.Layer = contour;
            Line5.Layer = contour;
            Line6.Layer = contour;
            Line7.Layer = contour;
            Line8.Layer = contour;
            Line9.Layer = refin;
            Line10.Layer = refin;
            dxf.AddEntity(Line1);
            dxf.AddEntity(Line2);
            dxf.AddEntity(Line3);
            dxf.AddEntity(Line4);
            dxf.AddEntity(Line5);
            dxf.AddEntity(Line6);
            dxf.AddEntity(Line7);
            dxf.AddEntity(Line8);
            dxf.AddEntity(Line9);
            dxf.AddEntity(Line10);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 1.0 / 2;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            LinearDimension dim1 = new LinearDimension(new Line(v1, v2), offset, 0, dimensionStyle);
            dim1.UserText = "B = " + Math.Round(B, 2);
            dxf.AddEntity(dim1);
            //尺寸2
            LinearDimension dim2 = new LinearDimension(new Line(v5, v4), -offset - (v5.Y - v4.Y) / 2.00, 0, dimensionStyle);
            dim2.UserText = "WF = " + Math.Round(WF, 2);
            dxf.AddEntity(dim2);
            //尺寸3
            LinearDimension dim3 = new LinearDimension(new Line(v12, v14), -offset, 270, dimensionStyle);
            dim3.UserText = "H = " + Math.Round(H, 2);
            dxf.AddEntity(dim3);
            //尺寸4
            LinearDimension dim4 = new LinearDimension(new Line(v2, v4), offset + 5 + WF / 2.00, 270, dimensionStyle);
            dim4.UserText = "LF = " + Math.Round(LF, 2);
            dxf.AddEntity(dim4);
            //尺寸5
            Angular2LineDimension dim5 = new Angular2LineDimension(new Line(v4, v3), new Line(v4, v5), offset, dimensionStyle);
            dim5.UserText = String.Format("EPSR={0}°", EPSR);
            dxf.AddEntity(dim5);
            //尺寸6
            Angular2LineDimension dim6 = new Angular2LineDimension(new Line(v4, v3), new Line(v4, v16), offset, dimensionStyle);
            dim6.UserText = String.Format("KAPR={0}°", KAPR);
            dxf.AddEntity(dim6);
            //尺寸7
            Angular2LineDimension dim7 = new Angular2LineDimension(new Line(v4, v5), new Line(v4, v17), offset, dimensionStyle);
            dim7.UserText = String.Format("KAPR={0}°", KAPR);
            dxf.AddEntity(dim7);
            //尺寸8
            LinearDimension dim8 = new LinearDimension(new Line(v6, v4), -offset - WF / 2.00, 270, dimensionStyle);
            dim8.UserText = "LH = " + Math.Round(LH, 2);
            dxf.AddEntity(dim8);
            //尺寸9
            LinearDimension dim9 = new LinearDimension(new Line(v9, v11), -offset - 5 - v9.Y + v4.Y, 0, dimensionStyle);
            dim9.UserText = "L = " + Math.Round(L, 2);
            dxf.AddEntity(dim9);
            //填充
            LwPolyline hatchpoly1 = new LwPolyline();
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v12));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v13));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v15));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v14));
            hatchpoly1.IsClosed = true;
            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)hatchpoly1.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, htype1, hnumst1, 45, 5, hline1, hatching);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
    }
}